package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Add implements Io{
    @Override
    public void work(BookList bookList) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入新增图书的名字");
        String name=scanner.nextLine();
        System.out.println("请输入新增图书的作者");
        String author=scanner.nextLine();
        System.out.println("请输入新增图书的价格");
        int price=scanner.nextInt();
        System.out.println("请输入新增图书的类型");
        String type=scanner.nextLine();
        Book book=new Book(name,author,price,type);
        int size=bookList.getUsedSize();
        if (size==bookList.getBooks().length){
            System.out.println("书架满了");
            return;
        }
        for(int i=0;i<size;i++)
        {
            if (bookList.getBook(i).getName().equals(name)){
                System.out.println("已经有这本书了");
                return;
            }
        }
        bookList.setBooks(size,book);
        bookList.setUsedSize(size+1);

    }
}
